﻿//--------------------------------------
// Copyright     : W.A.I.S. TECHNOLOGY 2003-2008 ; http://www.wais-fr.com ; email: infos@wais-fr.com
// Author        : Henri d'Orgeval
// Contributors  : 
// Last release  : 2007/10/29 (yy/mm/dd)
// Version       : 1.0.0.1
// Pattern       : "Real Time Trace"
// Internal name : TraceInfoFactory.vb (RealTimeTrace Factory that handles the business logic layer)
// Description   : this class contains all Factories needed to implement RealTimeTrace business logic layer.
//                 
// Framework     : v2.0.50727 and above
//
// Licence       : Microsoft Permisse Licence
// W.A.I.S provides this code in the hope that it will be useful, but WITHOUT ANY WARRANTY , either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.          
// This library is free software; you can redistribute it and/or modify it under the terms of the Microsoft Permissive Licence
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//---------------------------------------

using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;

namespace RealtimeTrace
{
    /// <summary>
    /// RealtimeTrace TraceInfo factory.
    /// </summary>
    internal sealed class TraceInfoFactory
    {
        private static System.Int32 _InstanceCount = 0;
        /// <summary>
        /// Gets the value of the ITraceInfo instance counter.
        /// </summary>
        private static int InstanceCount 
        {
            get
            {
                try
                {
                    if (_InstanceCount == System.Int32.MaxValue)
                    {
                        _InstanceCount = 0;
                    }
                    _InstanceCount += 1;
                    return _InstanceCount;
                }
                catch (Exception)
                {
                    return 0;
                }
                
            }
        }

        /// <summary>
        /// Creates and returns an instance of RealtimeTrace ITraceInfo interface.
        /// </summary>
        /// <param name="ex0">Exception object raised by the caller of the RealtimeTrace framework.</param>
        /// <returns></returns>
        internal static ITraceInfo CreateTraceInfo(System.Exception ex0)
        {
            try
            {
                // by default return a TraceInfo class instance.
                TraceInfo myDefaultTraceInfo = new TraceInfo(ex0, InstanceCount);
                return myDefaultTraceInfo;
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        /// Creates and returns an instance of RealtimeTrace ITraceInfo interface.
        /// </summary>
        /// <param name="ex0">Exception object raised by the caller of the RealtimeTrace framework.</param>
        /// <param name="args">List of values for each parameter of the method in which the exception has been raised.</param>
        /// <returns></returns>
        internal static ITraceInfo CreateTraceInfo(System.Exception ex0, params object[] args)
        {
            try
            {
                // by default return a TraceInfo class instance.
                TraceInfo myDefaultTraceInfo = new TraceInfo(ex0,InstanceCount, args);
                return myDefaultTraceInfo;
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        /// Makes the default constructor private.
        /// So that this Factory cannot be instanciated.
        /// </summary>
        private TraceInfoFactory()
        {

        }
    }
}
